package cn.us.eagle.generic.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.us.eagle.generic.dao.GenericDao;
import cn.us.eagle.generic.service.GenericService;

import java.io.Serializable;
import java.util.List;

/**
 * 共用式泛型Service实现类
 * 
 * @author ReasonZhong
 * 
 * @param <T>
 *            泛型类
 * @param <PK>
 *            泛型类主键
 */
@Service("genericService")
public class GenericServiceImpl<T, PK extends Serializable> implements
		GenericService<T, PK> {

	@Autowired
	@Qualifier("genericDao")
	private GenericDao<T, PK> genericDao;

	public T save(T model) {
		return genericDao.save(model);
	}

	public void saveOrUpdate(T model) {
		genericDao.saveOrUpdate(model);
	}

	public void update(T model) {
		genericDao.update(model);
	}

	public void merge(T model) {
		genericDao.merge(model);
	}

	public void delete(Class<T> entityClass, PK id) {
		genericDao.delete(entityClass, id);
	}

	public void deleteObject(T model) {
		genericDao.deleteObject(model);
	}

	public T get(Class<T> entityClass, PK id) {
		return genericDao.get(entityClass, id);

	}

	public int countAll(Class<T> entityClass) {
		return genericDao.countAll(entityClass);
	}

	public List<T> listAll(Class<T> entityClass) {
		return genericDao.listAll(entityClass);
	}

}
